<?php
class Merchant_Model_PlanRates
{
    protected $_dbTable;

    public function setDbTable($dbTable)
    {
        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('非正确的table类型！');
        }
        $this->_dbTable = $dbTable;
        return $this;
    }

    public function getDbTable()
    {
        if (null === $this->_dbTable) {
            $this->setDbTable('Merchant_Model_DbTable_PlanRates');
        }
        return $this->_dbTable;
    }

    //获取费率数据
    public function getRateByTypeAndQty($type, $qty)
    {
        $select = $this->getDbTable()->select()->where("type = ?",$type)
                                               ->where("range_end <= ? or (range_start < ? and range_end >= ?)", $qty)
                                               ->order('order');
        return  $this->_dbTable->fetchAll($select);
    }
    
    
    //按类型获取标准价格
    public function getListPriceByType($type)
    {
    	$select = $this->getDbTable()->select()->from($this->_dbTable,array('price','currency_code'))
    	                                       ->where("type = ?",$type);
											   
    	return  $this->_dbTable->fetchRow($select);
    }
    


}